<?php
// +----------------------------------------------------------------------
// | HisiPHP框架[基于ThinkPHP5.1开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2016-2021 http://www.HisiPHP.com
// +----------------------------------------------------------------------
// | HisiPHP承诺基础框架永久免费开源，您可用于学习和商用，但必须保留软件版权信息。
// +----------------------------------------------------------------------
// | Author: 橘子俊 <364666827@qq.com>，开发者QQ群：50304283
// +----------------------------------------------------------------------
namespace app\common\behavior;


class ModelEvent
{

	public function afterWrite($model)
	{
		return $this->_updateCache($model);
	}

	public function afterDelete($model)
	{
		return $this->_updateCache($model);
	}

	/**
	 * 调用服务层的更新缓存方法
	 *
	 * @author KING
	 * @date 2020年6月9日
	 *
	 * @param object $model
	 * @return boolean
	 */
	private function _updateCache($model) {
		$modelName = $model->getName();
		$serviceName = "\\app\\common\\service\\" . $modelName;
		if (class_exists($serviceName)) {
			$service = new $serviceName();
			if (method_exists($service, 'updateKVCache')) {
				call_user_func(array($service, 'updateKVCache'));
			}
		}
		return true;
	}
}